<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="内部订单号" prop="outTradeNo">
        <el-input
          v-model="queryParams.outTradeNo"
          placeholder="请输入内部订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分账人openId" prop="openId">
        <el-input
          v-model="queryParams.openId"
          placeholder="请输入分账人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月份" prop="day">
        <el-date-picker
          v-model="queryParams.day"
          type="month"
          placeholder="选择月"
          value-format="yyyy-MM"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="teamList">
      <el-table-column label="分账人openid" align="center" prop="openId" />
      <el-table-column
        label="分账总金额(元)"
        align="center"
        prop="divideTotal"
      />
      <el-table-column
        label="分账比例（%）"
        align="center"
        prop="orderPercentage"
      />
      <el-table-column
        label="分账金额(元)"
        align="center"
        prop="divideAmount"
      />
      <el-table-column label="分账类型" align="center" prop="cashoutType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.xw_cashout_type"
            :value="scope.row.cashoutType"
          />
        </template>
      </el-table-column>
      <el-table-column label="分账账号" align="center" prop="divideAccount" />
      <el-table-column label="分账账号名字" align="center" prop="divideDesc" />
      <el-table-column label="分账人类型" align="center" prop="userTypeName" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { queryByMonth } from "@/api/washer/statistics";
const date = new Date();

var year = date.getFullYear() + "";
var month =
  date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
export default {
  name: "Statistics",
  dicts: ["xw_cashout_type"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 终端团队表格数据
      teamList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        outTradeNo: null,
        openId: "",
        day: "",
      },
    };
  },
  created() {
    this.queryParams.day = year + "-" + month;
    this.getList();
  },
  methods: {
    /** 查询终端团队列表 */
    getList() {
      this.loading = true;
      queryByMonth({ ...this.queryParams }).then((response) => {
        this.teamList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.day = year + "-" + month;
      this.handleQuery();
    },
  },
};
</script>
